import { http } from "@/utils/http";

// 企业信息列表项类型
export interface EnterpriseInfoItem {
  id: number;
  contact_phone: string;
  company_name_cn: string;
  company_name_en: string;
  addres: string;
  pavilion: string;
  booth_number: string;
  booth_type: string;
  booth_area: number;
  product_category: string;
  contact_person: string;
  contact_email: string;
  contact_job: string;
  charge_person: string;
  charge_phone: string;
  charge_email: string;
  status: number;
  createtime: number;
  updatetime: number;
}

// 分页响应类型
export interface PaginationResponse<T> {
  code: number;
  msg: string;
  data: {
    total: number;
    page: number;
    limit: number;
    list: T[];
  };
}

// 详情响应类型
export interface DetailResponse<T> {
  code: number;
  msg: string;
  data: T;
}

// 企业信息列表响应类型
export type EnterpriseInfoListResponse = PaginationResponse<EnterpriseInfoItem>;

// 企业信息详情响应类型
export type EnterpriseInfoDetailResponse = DetailResponse<EnterpriseInfoItem>;

// 获取展商信息列表
export const getEnterpriseInfoList = (
  page: number,
  limit: number,
  contact_phone: string,
  keyword: string
) => {
  return http.request<EnterpriseInfoListResponse>(
    "get",
    "/api/exhibitor/list",
    {
      params: { page, limit, keyword, contact_phone }
    }
  );
};

// 申请展商信息
export const applyEnterpriseInfo = (data: EnterpriseInfoItem) => {
  return http.request<EnterpriseInfoDetailResponse>(
    "post",
    "/api/exhibitor/apply",
    { data }
  );
};

// 获取展商信息详情
export const getEnterpriseInfoDetail = (id: number) => {
  return http.request<EnterpriseInfoDetailResponse>(
    "get",
    "/api/exhibitor/detail",
    {
      params: { id }
    }
  );
};

// 申请展商信息数据类型
export type AddEnterpriseInfoData = {
  pavilion: string;
  booth_number: string;
  booth_type: string;
  booth_area: number;
  company_name_cn: string;
  company_name_en: string;
  product_category: string;
  contact_person: string;
  contact_phone: string;
  contact_email: string;
};

// 申请展商信息返回类型
export type AddEnterpriseInfoResult = {
  code: number;
  msg: string;
};

// 申请展商信息
export const addEnterpriseInfo = (data: AddEnterpriseInfoData) => {
  return http.request<AddEnterpriseInfoResult>("post", "/api/exhibitor/apply", {
    data
  });
};

// 更新展商信息
export const updateEnterpriseInfo = (data: EnterpriseInfoItem) => {
  return http.request<EnterpriseInfoDetailResponse>(
    "post",
    "/api/exhibitor/update",
    {
      data
    }
  );
};
